/*
 * This file is part of the Try! Engine project.
 *
 * Copyright 2010-2011 Emanuele Bertoldi. All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * You should have received a copy of the modified BSD License along with this
 * program. If not, see <http://www.opensource.org/licenses/bsd-license.php>
 */

#include "logic.h"
#include "userbehavior.h"
#include <agent.h>
#include <cameracontroller.h>
#include <keyboardlistener.h>
#include <lightemitter.h>
#include <animable.h>
#include <model3d.h>
#include <scenetransformable.h>
#include <application.h>

int main(int argc, char** argv)
{
    Logic app_logic;

    Try::Application app(&app_logic);

    // Set a camera to render the scene...
    Try::RenderWindow* win = app.window();
    Try::CameraNode camera("Camera", "pipelines/forward.pipeline.xml", win->width(), win->height(), 45.0f);
    camera.setTransform(Vector3(0, 10, 18), Vector3(-30, 0, 0), Vector3::Identity);
    win->setActiveCamera(&camera);

    // ...add a ground...
    Try::Object env("Environment");
    Try::Model3D env_model(&env, "models/platform/platform.scene.xml");

    // ...add two agents...
    // * the first one is controlled by the CPU,
    // * the second one is controlled by the user.
    Try::Object agent1("Agent1");
    Try::Model3D a1_model(&agent1, "models/knight/knight.scene.xml");
    a1_model.addAnimation("animations/knight_order.anim");
    a1_model.addAnimation("animations/knight_order.anim");
    a1_model.addAnimation("animations/knight_attack.anim");
    a1_model.setPosition(Vector3(-5, 0, 0));
    a1_model.setScale(Vector3(0.06, 0.06, 0.06));
    a1_model.lookAt(Vector3(0, 0, 0));
    Try::Agent ia1(&agent1);

    Try::Object agent2("Agent2");
    Try::Model3D a2_model(&agent2, "models/knight/knight.scene.xml");
    a2_model.addAnimation("animations/knight_order.anim");
    a2_model.setPosition(Vector3(5, 0, 0));
    a2_model.setScale(Vector3(0.06, 0.06, 0.06));
    a2_model.lookAt(Vector3(0, 0, 0));
    Try::KeyboardListener kbd_lst(&agent2);

    // ...and also a light.
    Try::Object light("Light");
    Try::LightEmitter light_emitter(&light, light.name());
    light_emitter.setPosition(Vector3(0, 25, 40));

    // Finally, initialize the logic.
    app_logic.watchObject(&agent1);
    app_logic.watchObject(&agent2);
    app_logic.ub.watchObject(&agent2);
    app_logic.bt1.setEnemy(a2_model.sceneNode());
    app_logic.bt2.setEnemy(a2_model.sceneNode());

    return app.run();
}
